/*
Philip Dilse
dilsep
Assignment 3

unit test for isGameOver()
*/

#define NUM_TESTS 500

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include "dominion.h"
#include "dominion_helpers.h"

int main() {
    int i, j;
    int calcGameOver;
    int emptyCount;
    int gameOver;
    struct gameState *gs = newGame();
 
    // set up random number gen
    srand(time(NULL));

    for (i = 0; i < NUM_TESTS; i++) {
        emptyCount = 0;
        gameOver = 0;

        // initialize supply to random values between -1 and 10 inclusive
        for (j = curse; j <= treasure_map; j++) {
            gs->supplyCount[j] = rand() % 12 - 1;
        }
    
        if (gs->supplyCount[province] == 0) {
            gameOver = 1;
        } else {
            for (j = curse; j <= treasure_map; j++) {
                if (gs->supplyCount[j] == 0) {
                    emptyCount++;
                }
            }
        }
        if (emptyCount >= 3)
            gameOver = 1;

        calcGameOver = isGameOver(gs);
        if (gameOver != calcGameOver) {
            printf("isGameOver() error: expected=%d calculated=%d\n", gameOver, calcGameOver);
        } 
    }
    free(gs);
    return 0;
}
